package cn.tips.dmp.supports.global.handler;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 自定义注册全局http错误发生跳转处理URL
 * <p>
 * 处理逻辑参照:{@link CustomErrorPageController}
 *
 * @author pkb
 */
@Component
public class CustomErrorPageRegistrar implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage[] errorPages = new ErrorPage[5];
        errorPages[0] = new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400");
        errorPages[1] = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401");
        errorPages[2] = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
        errorPages[3] = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/405");
        errorPages[4] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
        registry.addErrorPages(errorPages);
    }
}
